package com.ctbu.tools;

import lombok.Data;

import java.io.Serializable;

@Data
public class ResponseResult<T> implements Serializable {

    /**
     * 返回数据的状态码
     */
    private Integer code;

    /**
     * 返回的提示信息
     */
    private String message;

    /**
     * 返回的结果数据
     */
    private T data;

    /**
     * 定义通用返回结果：成功缺省提示信息
     */
    public static <T> ResponseResult<T> success(T data){
        ResponseResult<T> result = new ResponseResult<>();
        result.setData(data);
        result.setCode(HttpStatusEnum.SUCCESS.code);
        return result;
    }
    /**
     * 定义通用返回结果：成功 带提示信息
     */
    public static <T> ResponseResult<T> success(T data,String message){
        ResponseResult<T> result = new ResponseResult<>();
        result.setData(data);
        result.setCode(HttpStatusEnum.SUCCESS.code);
        result.setMessage(message);
        return result;
    }

    /**
     * 定义通用返回结果：错误缺省提示信息
     * @param httpStatusEnum
     * @return ResponseResult<T>
     * @param <T>
     */
    public static <T> ResponseResult<T> error(HttpStatusEnum httpStatusEnum){
        ResponseResult<T> result = new ResponseResult<>();
        result.setCode(httpStatusEnum.code);
        result.setMessage(httpStatusEnum.message);
        return result;
    }

    /**
     * 定义通用返回结果：错误 自定义提示信息
     * @param httpStatusEnum
     * @return ResponseResult<T>
     * @param <T>
     */
    public static <T> ResponseResult<T> error(HttpStatusEnum httpStatusEnum,String message){
        ResponseResult<T> result = new ResponseResult<>();
        result.setCode(httpStatusEnum.code);
        result.setMessage(message);
        return result;
    }

}
